$(function(){
    obj.init();
});

var obj = new JsFun();
function JsFun(){
    'use strict';
    return {
        init: function () {
            new xhForm($('#xh_form')).parse();
            $('.school').eq(0).select2();
            this.listener();
        },
        listener: function () {
            var $this = this;
            $('#bt_modal_confirm', parent.document).unbind('click').bind('click',function () {
                $this.funObj().submitForm();
            });
        },
        funObj: function(){
            var $this = this;
            return {
                submitForm: function () {
                    var schoolId = $('.school').val();
                    var cls = $('.class').val();
                    if (! schoolId) {
                        window.top.xhTop.showError('未选择学校！');
                        return false;
                    }
                    if (! cls && ! xhTool.getQuery('teacher')) {
                        window.top.xhTop.showError('未填写班级！');
                        return false;
                    }
                    $.ajax({
                        url:baseUrl+'school/doChangeSchool',
                        data:{'schoolId':$('.school').val(), 'ids': ids, 'class': cls},
                        type:'POST',
                        success:function (data) {
                            window.top.xhTop.showSuccess(data.msg);
                            window.top.xhTop.getActiveFrame().location.reload();
                            window.top.xhTop.closeModal();
                        },
                        error:function (data) {
                            // console.log(data)
                            window.top.swal(
                                data['responseJSON'].error,
                                '',
                                'error'
                            );
                        }
                    });
                }
            }
        }
    }
}

